#ifndef UR_LIGHTS_H_
#define UR_LIGHTS_H_

// Default data boundaries
#define UR_LIGHTS_LIGHTS_MIN 0
#define UR_LIGHTS_LIGHTS_MAX 511

#include "AbstractData.h"
/*
* class URLights
* 
* Represents lights data for sentence to be sent from USTAV Router to USTAV Server.
*
*  Created on: 22.1.2012.
*      Author: Hetcheem
*
* STATUS               min         max  bytes  + comma    unit  data type
* -----------------------------------------------------------------------
* Lights                 0         511      3        4       ?        int
* -----------------------------------------------------------------------
* TOTAL                                     3        4
* BASE + STATUS                                     22
*/
class URLights : public AbstractData
{
private:
    // Data members
    int m_code;

    // Data handling
    int SerializeSentence(std::stringstream& stream, const bool& isSending)
    {
        // Call base class serialization
        AbstractData::SerializeSentence(stream, isSending);

        if (isSending)
        {
            // Send data to stream
            stream << m_code;
        }
        else
        {
            int code;

            // Recieve data from stream
            stream >> code;

            // Set the values
            SetLightsCode(code);
        }

        return 0;
    }

public:
    // Constructor
    URLights() : AbstractData("URLIG"),
        m_code(0)
    {}

    // Get
    inline const int& GetLightsCode() { return m_code; }

    // Set
    int SetLightsCode(const int& value)
    {
        if (value > UR_LIGHTS_LIGHTS_MAX)
        {
            m_code = UR_LIGHTS_LIGHTS_MAX;
            return 666;
        }
        else if (value < UR_LIGHTS_LIGHTS_MIN)
        {
            m_code = UR_LIGHTS_LIGHTS_MIN;
            return -666;
        }

        m_code = value;
        return 0;
    }
};

#endif /* UR_LIGHTS_H_ */
